﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection conn = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Employee"] == null)
        {
            Response.Redirect("~/Login.aspx");
        }
        else
        {
            conn = Database.GetConnection();
            GetInfoManager();
        }    
    }
    public void GetInfoManager()
    {
        DataTable dtManager =(DataTable) Session["Employee"];
        lblName.Text = dtManager.Rows[0][3].ToString();
        lblEmail.Text = dtManager.Rows[0][4].ToString();
        lblAddress.Text = dtManager.Rows[0][5].ToString();
        lblRole.Text = GetRoles();
        lblDepartment.Text = GetDepartment();
    }
    public string GetRoles()
    {
        DataTable dtManager = (DataTable)Session["Employee"];
        string idroles = dtManager.Rows[0][6].ToString();
        SqlDataAdapter adapter = new SqlDataAdapter("select * from Roles where Roles_ID = "+idroles+"", conn);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        return dt.Rows[0][1].ToString();
    }
    public string GetDepartment()
    {
        DataTable dtManager = (DataTable)Session["Employee"];
        string iddepartment = dtManager.Rows[0][7].ToString();
        SqlDataAdapter adapter = new SqlDataAdapter("select * from Department where D_ID = "+iddepartment+"", conn);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        return dt.Rows[0][1].ToString();
    }

    protected void lbLogout_Click(object sender, EventArgs e)
    {
        Session["Emoloyee"] = null;
        Response.Redirect("~/Login.aspx");
    }
}
